﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GWApplication
{

    /// <summary>
    /// 为所有的概念化数据提供容器类
    /// </summary>
    [Serializable]
    public class ConceptualData
    {


        #region 事件

        [field:NonSerialized]
        public event EventHandler CMAdded;


         [field: NonSerialized]
        public event EventHandler CMRemoved;



        #endregion


        Dictionary<string, ConceptualModel> _modelsForLook = new Dictionary<string, ConceptualModel>();

        List<ConceptualModel> _models = new List<ConceptualModel>();

        public List<ConceptualModel> Models
        {
            get { return _models; }
           

        }


        public ConceptualModel GetConceptualModel(string id)
        {
            if (this._modelsForLook.ContainsKey(id))
            {
                return this._modelsForLook[id];
                
            }

            return null;

        }



        public void Add(ConceptualModel model)
        {

            if (!this._modelsForLook.ContainsKey(model.Id))
            {

                this._modelsForLook.Add(model.Id,model);

                this._models.Add(model);


                if (CMAdded != null)
                {
                    CMAdded(model, EventArgs.Empty);

                }

                
            }

            
 


        }


        public void Remove(string id)
        {


            if (this._modelsForLook.ContainsKey(id))
            {
                ConceptualModel cm = this._modelsForLook[id];

                this._models.Remove(cm);
                this._modelsForLook.Remove(id);

                if (CMRemoved != null)
                {
                    CMRemoved(cm, EventArgs.Empty);

                }


                
            }



           
 
        }





    }
}
